package br.urca.impl;

import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.transaction.Transactional;

import br.urca.dao.FormaIngressoDAO;
import br.urca.model.FormaIngresso;

@Transactional
public class JPAFormaIngressoDAO implements FormaIngressoDAO {
	
	private EntityManager manager;
	
	public JPAFormaIngressoDAO() {
		this(null);
	}
	
	@Inject
	public JPAFormaIngressoDAO(EntityManager manager) {
		this.manager = manager;
	}

	@Override
	public FormaIngresso getByCodigo(String codigo) {
		try {
			return this.manager
					.createQuery(
							"SELECT f FROM FormaIngresso f "
									+ "WHERE f.codigo = :codigo ",
							FormaIngresso.class).setParameter("codigo", codigo)
					.getSingleResult();
		} catch (Exception e) {
			return null;
		}
	}

}
